{* $Id$ *}
{include_core file="admin/lib/header.html" title="配置展示"}
<div class="page-header border-bottom clearfix">
  <h2 class="left">配置<span>{if $info}编辑{else}添加{/if}配置</span></h2>
  <a href="{AnUrl('setting/admin')}" class="btn btn-default btn-sm right">&lt;&nbsp;返回配置列表</a>
</div>
<!--start:配置新增-->
<div class="add-form">
  <form class="js_creatForm" action="{AnUrl('setting/admin/save')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$info.id}">
    <table class="table" cellpadding="0" cellspacing="0">
      <tr>
        <th><label for="" class="add-f-label">配置名称：</label></th>
        <td>
          <input name="info[title]" value="{$info.title}" type="text" class="add-f-ipt1 js_title">
          <div class="tips"></div>
        </td>
      </tr>
      <tr>
        <th><label for="" class="add-f-label">配置字段名：</label></th>
        <td>
          <input name="info[field]" value="{$info.field}" type="text" {if $id}disabled class="gray add-f-ipt1 js_field"{else}class="add-f-ipt1 js_field"{/if}>
          <div class="tips"></div>
        </td>
      </tr>
      <tr>
        <th valign="top"><label for="" class="add-f-label">配置字段值：</label></th>
        <td>
          <textarea class="add-f-area js_value" name="info[value]">{$info.value}</textarea>
          <div class="tips"></div>
        </td>
      </tr>
      {*<tr>
        <th valign="top"><label for="" class="add-f-label">配置封面：</label></th>
        <td class="perUpOuter">
          <div class="clearfix">
            <div class="btn-upload left">
              <a href="javascript:void(0);"><i class="icon-upload"></i>上传封面</a>
              <input class="js_cover js_upFile"  type="file" name="cover">
            </div>
            <span class="tips left">&nbsp;&nbsp;&nbsp;配置封面图</span>
          </div>
          <div class="js_upFileBox">
              {if $info.cover}
              <img src="{_image($info.cover)}" width="360">
              {/if}
          </div>
        </td>
      </tr>*}
      <tr><th>&nbsp;</th><td class="noborder"><button type="submit" class="btn btn-success js_submit">&nbsp;&nbsp;&nbsp;确认&nbsp;&nbsp;&nbsp;</button></td></tr>
    </table>
  </form>
</div>
<!--end:配置新增-->
<script>
var resName = 'setting';
function setNum(thisClass, maxNum) {
  var presentNum = $('.'+thisClass).val().length;
  var remainNum  = maxNum - presentNum;
  if (remainNum < 0) {
    $('.'+thisClass).val($('.'+thisClass).val().substr(0,maxNum));
    $('.'+thisClass+'Num').text(0);
  } else {
    $('.'+thisClass+'Num').text(remainNum);
  }
}

$(function(){
  // 初始化剩余字数
  setNum('js_title', 30);
  $('.js_title').keyup(function(){
    setNum('js_title', 30);
  });
  
  // 提交验证
  $('.js_submit').click(function(e){
    e.preventDefault();
    var title      = $.trim($('.js_title').val());
    var field      = $.trim($('.js_field').val());
    var value      = $.trim($('.js_value').val());
    // var cover      = $.trim($('.js_cover').val());

    if (!title) {
      showMsg('配置名称不能为空');
      return;
    }
    if (!field) {
      showMsg('字段名不能为空');
      return;
    }
    if (!value) {
      showMsg('字段值不能为空');
      return;
    }
    $('.js_creatForm').submit();
  });
  
  // 上传图片预览
  $(".js_upFile").each(function(i){
    $(this).change(function(e){
      handleFileSelect($(this));
    });
  });
});
</script>
{include_core file="admin/lib/footer.html"}